<template>
  <div>
    <el-table
      ref="tabledata"
      :data="tabledate"
      height="220"
      @cell-mouse-enter="mouseEnter"
      @cell-mouse-leave="mouseLeave"
    >
      <!-- <el-table-column type="selection"></el-table-column> -->
      <el-table-column
        v-for="header in tableHeaders"
        :key="header.prop"
        :prop="header.prop"
        :label="header.label"
      ></el-table-column>

      <!-- <el-table-column
      :label="item.label"
      :prop="item.prop"
      v-for="item in tableHeaders"
      :key="item.prop"
      ></el-table-column>-->
      <!-- <el-table-column label="英文名" prop="value"></el-table-column>
      <el-table-column label="中文名" prop="label"></el-table-column>-->
    </el-table>
  </div>
</template>
   
  <script>
export default {
  name: "tableDemo",
  props: {
    tableHeaders: {
      type: Array,
      required: true, //必填
      default: [] //默认值
    },

    tabledate: {
      type: Array,
      required: true, //必填
      default: [] //默认值
    }
  },
  data() {
    return {
      table_interval: null
    };
  },
  mounted() {
    this.dataScrolling();
  },
  methods: {
    //数据滚动
    dataScrolling: function() {
      var table = this.$refs.tabledata;
      var top = table.bodyWrapper;
      this.table_interval = setInterval(() => {
        // top.scrollTop = 0;
        top.scrollTop += 1;

        if (top.clientHeight + Math.ceil(top.scrollTop) == top.scrollHeight) {
          top.scrollTop = 0;
        }
      }, 100);
    },
    //鼠标进入，停止滚动
    mouseEnter: function() {
      clearInterval(this.table_interval);
      this.table_interval = null;
    },
    //鼠标离开，开始滚动
    mouseLeave: function() {
      this.dataScrolling();
    }
  }
};
</script>